package org.example.design.redis;

import redis.clients.jedis.Jedis;

import java.util.List;

public class redisListDemo {
    public static void main(String[] args) {
        Jedis jedis=new Jedis("",6379);
        jedis.auth("");
        jedis.select(0);

        testRpushAndRpop(jedis);
    }
    //测试lpush和lpop
    private static void testLpushAndLpop(Jedis jedis) {
        long n = jedis.lpush("key", "1", "2", "3", "4");
        System.out.println(n);
        String value = jedis.lpop("key");
        System.out.println(value);
        value = jedis.lpop("key");
        System.out.println(value);
        value = jedis.lpop("key");
        System.out.println(value);
        value = jedis.lpop("key");
        System.out.println(value);
        value = jedis.lpop("key");
        System.out.println(value);
    }
    //测试rpush和rpop
    private static void testRpushAndRpop(Jedis jedis) {
        long n = jedis.rpush("key", "1", "2", "3", "4");
        System.out.println(n);
        String value = jedis.rpop("key");
        System.out.println(value);
        value = jedis.rpop("key");
        System.out.println(value);
        value = jedis.rpop("key");
        System.out.println(value);
        value = jedis.rpop("key");
        System.out.println(value);
        value = jedis.rpop("key");
        System.out.println(value);
    }
    //测试lrange
    private static void testLrange(Jedis jedis) {
        jedis.rpush("key", "1", "2", "3", "4");
        List<String> values = jedis.lrange("key", 1, 3);
        System.out.println(values);
    }
}
